package com.guigu.ssq.servlet;

import com.google.gson.Gson;
import com.guigu.ssq.mapper.SsqMapper;
import com.guigu.ssq.util.MapperFactory;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "CountServlet", value = "/count.do")
public class CountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
        String date1 = request.getParameter("date1");
        String date2 = request.getParameter("date2");
        Gson gson = new Gson();


        MapperFactory mf =new MapperFactory();
        SsqMapper mapper = mf.getMapper();
       int count= mapper.count(date1,date2);

        System.out.println("条数"+ count);
        String json = gson.toJson(count);
        System.out.println(json);
        response.getWriter().print(json);

    }
}
